home *** CD-ROM | disk | FTP | other *** search
/ Mac Mania 2 / MacMania 2.toast / Demo's / Tools&Utilities / Programming / Mac wt 0.04 Folder / MacWT.fat 0.04 / Mac WT source / MacMain.c < prev    next >
Encoding:
Text File  |  1994-05-11  |  15.0 KB  |  767 lines  |  [TEXT/MMCC]

  1. //==================================================================
  2. // MacMain.c                                        <tur 01-May-94>
  3. //
  4. //    A quickie Macintosh main program to be bolted onto 
  5. //    Chris Laurel's "wt" thingy...
  6. //
  7. //    Comments, Bug Reports/Fixes, etc, to turly@isltd.insignia.com
  8. //
  9. //==================================================================
  10.  
  11. #ifndef    __QUICKDRAW__
  12. #include "LoadMacHeaders.h"
  13. #endif    /* __QUICKDRAW__ */
  14.  
  15. #include <stdio.h>
  16. #include <stdarg.h>
  17. #include <string.h>
  18. #if !(THINK_C || THINK_CPLUS)
  19. #include <Strings.h>        /* p2cstr, etc. */
  20. #endif
  21. #include <AppleEvents.h>
  22. #include "DirScrnWrite.h"
  23. #include "Failure.h"
  24. #include "error.h"
  25. #include "framebuf.h"
  26. #include "graphics.h"
  27. #include "MacGame.h"
  28.  
  29. #if applec || __ppcc
  30. #include <PLStringFuncs.h>
  31. #endif
  32.  
  33.  
  34. /**/
  35.  
  36.  
  37. #define    kMinMem    (640<<10)                    /* Absolute minimum memory required */
  38.  
  39. enum {kTab = 9, kSpace = 20, kEsc = 27};    /* Hacky ASCII codes */
  40.  
  41. enum {rMBarID = 128,
  42.       rAppleMenuID = 128, rFileMenuID, rEditMenuID};
  43.  
  44. enum {rAppleAbout = 1,
  45.       rFileNewGame = 1, rFileDiv1, rFileShowFPS, rFileUseQD, rFilePause, rFileDiv2, rFileQuit};
  46.  
  47. enum {rFatalErrorAlert = 32765,
  48.       rAboutAlert = 32766,
  49.       rBadStartAlert = 32767};
  50.  
  51. enum {rWindowID = 128};
  52.  
  53. enum {rUtilityStrs = 128,
  54.       rStrPause = 1, rStrContinue, rDirWrite, rNoDirWrite};
  55.  
  56.  
  57. /**/
  58.  
  59.  
  60. static void doMenu(long mResult);
  61. pascal StringPtr PLstrcpy(StringPtr dst, StringPtr src);
  62. pascal StringPtr PLstrcat(StringPtr dst, StringPtr str2);
  63.  
  64.  
  65. /**/
  66.  
  67.  
  68. EventRecord    gTheEvent;
  69. Boolean        gDone = false;
  70. Boolean        gUseQuickDraw = false;
  71. Boolean        gPaused = false;
  72. Boolean        gShowFPS = true;
  73. Boolean        gGameOn = false;
  74. char        gWorldFileName[256];
  75. Str15        gWTVersion = "\pUnknown";
  76.  
  77. #if    __ppcc
  78. QDGlobals     qd;
  79. #endif
  80.  
  81.  
  82. /**/
  83.  
  84.  
  85. const unsigned char    nullStr[1] = {0};
  86.  
  87.  
  88. /**/
  89.  
  90.  
  91. static WindowPtr    gMainWindow;
  92. static int            gYieldTime = 0;
  93. static SysEnvRec    gTheSysEnv;
  94. static MenuHandle    gAppleMenu, gFileMenu, gEditMenu;
  95. static Boolean        gInBackground = false;
  96.  
  97.  
  98. /**/
  99.  
  100.  
  101. static int initPal(PaletteHandle pal)
  102. {
  103.     return LoadPaletteFromFile(pal, nil);    // pickup default palette
  104. }
  105.  
  106.  
  107. /**/
  108.  
  109.  
  110. static void showFailure(ConstStr255Param unixStr)
  111. {
  112.     Str255            macStr;
  113.     int                i;
  114.  
  115.     // Disgusting hackery to convert LFs to CRs for the Mac error string.
  116.  
  117.     macStr[0] = unixStr[0];
  118.  
  119.     for (i = 1; i <= unixStr[0]; ++i)
  120.         macStr[i] = (unixStr[i] == 10) ? 13 : unixStr[i];
  121.  
  122.     ParamText(macStr, nullStr, nullStr, nullStr);
  123.     Alert(rFatalErrorAlert, nil);
  124. }
  125.  
  126.  
  127. /**/
  128.  
  129.  
  130. void fatal_error(char *fmt, ...)
  131. {
  132.     va_list    args;
  133.     char    buf[256];
  134.  
  135.     va_start(args, fmt);
  136.     buf[0] = vsprintf(buf+1, fmt, args);
  137.     va_end(args);
  138.  
  139.     showFailure((StringPtr)buf);
  140.     ExitToShell();
  141. }
  142.  
  143.  
  144. /**/
  145.  
  146.  
  147. #ifndef __PLSTRINGFUNCS__
  148.  
  149. // Grrr -- need to hack together my own versions of PLstrcpy and PLstrcat for THICK C and MWC/PPC!
  150.  
  151. pascal StringPtr PLstrcpy(StringPtr str1, StringPtr str2)
  152. {
  153.     unsigned char    *cp = str1;
  154.     unsigned        len = *(unsigned char *)str2;
  155.  
  156.     // Need to copy length byte as well, remember...
  157.  
  158.     do {
  159.         *cp++ = *str2++;
  160.     } while (len--);
  161.  
  162.     return str1;
  163. }
  164.  
  165.  
  166. /**/
  167.  
  168.  
  169. pascal StringPtr PLstrcat(StringPtr str1, StringPtr str2)
  170. {
  171.     unsigned char    *cp = str1;
  172.     unsigned        len1 = *(unsigned char *)str1,
  173.                     len2 = *(unsigned char *)str2;
  174.  
  175.     if ((len1 + len2) >= 255) {
  176.         DebugStr((unsigned char *)"\pString concatenation -- dest too big!");
  177.         return 0;
  178.     }
  179.  
  180.     cp += len1 + 1;                        // skip to end of str1
  181.     *(unsigned char *)str1 += len2;        // adjust length byte
  182.     ++str2;                                // don't copy "str2" length byte
  183.  
  184.     while (len2--)
  185.         *cp++ = *str2++;
  186.  
  187.     return str1;
  188. }
  189.  
  190. #endif /* __PLSTRINGFUNCS__ */
  191.  
  192.  
  193. /**/
  194.  
  195.  
  196. #ifndef    __STRINGS__
  197.  
  198. char *p2cstr(StringPtr pStr)
  199. {
  200.     unsigned    len;
  201.     char        *cp;
  202.  
  203.     len = *(unsigned char *)pStr;
  204.     cp = (char *)pStr;
  205.  
  206.     while (len--) {
  207.         cp[0] = cp[1];                    // slide chars backwards (over length byte)
  208.         ++cp;
  209.     }
  210.  
  211.     *cp = 0;                            // terminate C-string
  212.  
  213.     return (char *)pStr;                // return now C-style string
  214. }
  215.  
  216. StringPtr c2pstr(char *cStr)
  217. {
  218.     unsigned char *cp;
  219.     unsigned len, cStrLen;
  220.  
  221.     cStrLen = len = strlen(cStr);
  222.  
  223.     if (len > 255)                        // perhaps we should have a _DebugStr here...
  224.         len = 255;                        // (don't overrun the max length)
  225.  
  226.     cp = (unsigned char *)cStr + len - 1;
  227.  
  228.     while (len--) {
  229.         cp[1] = cp[0];                    // slide chars forward (make room for length byte)
  230.         --cp;
  231.     }
  232.  
  233.     *cStr = cStrLen;                    // bung in length byte
  234.  
  235.     return (StringPtr)cStr;                // return now-pascal style string
  236. }
  237.  
  238. #endif    /* __STRINGS__ */
  239.  
  240.  
  241. /**/
  242.  
  243.  
  244. static int PathNameFromDirID(int vRefNum, long dirID, Str255 fullPathName)
  245. {
  246.     Str255        dirName;
  247.     DirInfo        dirInf;
  248.     OSErr        err;
  249.  
  250.     *fullPathName = 0;
  251.  
  252.     dirInf.ioNamePtr = dirName;
  253.     dirInf.ioDrParID = dirID;
  254.  
  255.     do {
  256.         dirInf.ioVRefNum = vRefNum;
  257.         dirInf.ioFDirIndex = -1;                 // -1 means use ioDrDirID…
  258.         dirInf.ioDrDirID = dirInf.ioDrParID;
  259.  
  260.         err = PBGetCatInfoSync((CInfoPBPtr)&dirInf);
  261.  
  262.         if (err == noErr) {
  263.             dirName[++dirName[0]] = ':';
  264.  
  265.             if (dirName[0] + fullPathName[0] > 255)
  266.                 err = bdNamErr;                 // too big to eat!
  267.             else {
  268.                 PLstrcat(dirName, fullPathName);
  269.                 PLstrcpy(fullPathName, dirName);
  270.             }
  271.         }
  272.  
  273.     } while (dirInf.ioDrDirID != fsRtDirID && err == noErr);
  274.  
  275.     return err;
  276.  
  277. }    // PathNameFromDirID
  278.  
  279.  
  280. /**/
  281.  
  282.  
  283. /* Standard AppleEvents stuff.
  284. **    We support only the required AppleEvents.
  285. **    We •really• support only the OpenDoc and Quit AppleEvents!
  286. */
  287. static OSErr AEGotRequiredParams(AppleEvent *aevt)
  288. {
  289.     register OSErr    err;
  290.     Size            actualSize;
  291.     DescType        typeCode;
  292.  
  293.     // see if we've got all the parameters...
  294.  
  295.     err = AEGetAttributePtr(aevt, keyMissedKeywordAttr, typeWildCard, &typeCode,
  296.                             NULL, 0, &actualSize);
  297.  
  298.     if (err == errAEDescNotFound)    // No "missed keyword" attribute ==> got all required params
  299.         err = noErr;
  300.     else
  301.     if (err == noErr)                // "missed keyword" attribute exists ==> missed at least one
  302.         err = errAEParamMissed;
  303.  
  304.     return err;
  305. }
  306.  
  307.  
  308. /**/
  309.  
  310.  
  311. /* AEOpenApp -- the “open application” AppleEvent.
  312. ** Return noErr UNLESS there are “missing parameters” (a good trick, since
  313. ** this AppleEvent doesn’t have any!)
  314. **
  315. */
  316. static pascal OSErr AEOpenApp(AppleEvent *request, AppleEvent *reply, long handlerRefCon)
  317. {
  318.     return AEGotRequiredParams(request);
  319. }
  320.  
  321.  
  322. /**/
  323.  
  324.  
  325. /* AEOpenDocs
  326. **    Fetch the list of things to be opened.
  327. */
  328. static pascal OSErr AEOpenDocs(register AppleEvent *request, AppleEvent *reply, long ref)
  329. {
  330.     return errAEEventNotHandled;
  331. }
  332.  
  333.  
  334. /**/
  335.  
  336.  
  337. /* AEPrintDocs -- we can’t print documents… */
  338. static pascal OSErr AEPrintDocs(AppleEvent *request, AppleEvent *reply, long ref)
  339. {
  340.     return errAEEventNotHandled;
  341. }
  342.  
  343.  
  344. /**/
  345.  
  346.  
  347. static pascal OSErr AEQuitApp(AppleEvent *request, AppleEvent *reply, long ref)
  348. {
  349.     register OSErr    err;
  350.  
  351.     err = AEGotRequiredParams(request);
  352.  
  353.     if (err == noErr)
  354.         doMenu((rFileMenuID << 16) | rFileQuit);
  355.  
  356.     return err;
  357. }
  358.  
  359.  
  360. /**/
  361.  
  362.  
  363. static void init(void)
  364. {
  365.     int                    err;
  366.     Handle                mbh;
  367.     WStateData            **wHndl;
  368.     StandardFileReply    sfReply;
  369.     Str255                titleStr;
  370.     unsigned char        **versRsrc;
  371.  
  372.     MaxApplZone();                            /* so code segments load at top… */
  373.  
  374.     FlushEvents(everyEvent - diskMask, 0);    /* so disks inserted while app starts */
  375.                                             /* all work OK (no dead disks) */
  376.     InitGraf(&qd.thePort);                    /* ritual incantation #2423: */
  377.     InitFonts();
  378.     InitWindows();
  379.     InitMenus();
  380.     TEInit();
  381.     InitDialogs(nil);
  382.     InitCursor();
  383.  
  384.     gShowFailProc = showFailure;        // for failure purposes...
  385.  
  386.     /* Set up menus... */
  387.     mbh = GetNewMBar(rMBarID);
  388.     FailNil(mbh);
  389.     SetMenuBar(mbh);                    // install the menubar!
  390.  
  391.     gAppleMenu = GetMHandle(rAppleMenuID);    // add the DAs to the Apple menu
  392.     FailNil(gAppleMenu);
  393.     AddResMenu(gAppleMenu, 'DRVR');
  394.  
  395.     gFileMenu = GetMHandle(rFileMenuID);
  396.     FailNil(gFileMenu);
  397.     SetItemMark(gFileMenu, rFileUseQD, (gUseQuickDraw) ? checkMark : noMark);
  398.     SetItemMark(gFileMenu, rFileShowFPS, (gShowFPS) ? checkMark : noMark);
  399.  
  400.     gEditMenu = GetMHandle(rEditMenuID);
  401.     FailNil(gEditMenu);
  402.  
  403.     DrawMenuBar();
  404.  
  405.     /* Catch as many failures as possible now... */
  406.  
  407.     err = SysEnvirons(curSysEnvVers, &gTheSysEnv);
  408.     if (err || !gTheSysEnv.hasColorQD || gTheSysEnv.systemVersion < 0x0700 ||
  409.                             ((long)GetApplLimit() - (long)ApplicZone()) < kMinMem) {
  410.         StopAlert(rBadStartAlert, nil);
  411.         ExitToShell();
  412.     }
  413.  
  414.     // remember the version
  415.  
  416.     if ((versRsrc = (unsigned char **)Get1Resource('vers', 1)) != 0)
  417.         PLstrcpy(gWTVersion, *versRsrc + 6);
  418.  
  419.     // get an event or two...
  420.     (void)GetNextEvent(0, &gTheEvent);
  421.     (void)GetNextEvent(0, &gTheEvent);
  422.  
  423.     // Install our standard AppleEvent handlers
  424.     // Careful! My MPW PPCC and Metrowerks appear to be using different headers.
  425.  
  426. #ifndef    NewAEEventHandlerProc
  427. #    ifdef    NewEventHandlerProc
  428. #        define    NewAEEventHandlerProc    NewEventHandlerProc
  429. #    else
  430. #        define    NewAEEventHandlerProc(proc)    (EventHandlerProcPtr)proc
  431. #    endif
  432. #endif
  433.  
  434.     err = AEInstallEventHandler(kCoreEventClass, kAEQuitApplication, NewAEEventHandlerProc(AEQuitApp), kAEQuitApplication, false);
  435.     if (err == noErr)
  436.         err = AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments, NewAEEventHandlerProc(AEOpenDocs), kAEOpenDocuments, false);
  437.     if (err == noErr)
  438.         err = AEInstallEventHandler(kCoreEventClass, kAEPrintDocuments, NewAEEventHandlerProc(AEPrintDocs), kAEPrintDocuments, false);
  439.     if (err == noErr)
  440.         err = AEInstallEventHandler(kCoreEventClass, kAEOpenApplication, NewAEEventHandlerProc(AEOpenApp), kAEOpenApplication, false);
  441.  
  442.     FailOSErr(err);
  443.  
  444.     InitDirScrnWrite();
  445.  
  446.     PLstrcpy(titleStr, (StringPtr)"\pling2.world");
  447.     strcpy((char *)gWorldFileName, ":wt:worlds:ling2.world");
  448.  
  449.     // starting up with shift key down ==> allow the user to use a different world file!
  450.  
  451.     if (gTheEvent.modifiers & shiftKey) {
  452.         SFTypeList            sfList = {'TEXT'};
  453.         Str255                worldName;
  454.  
  455.         StandardGetFile(nil, 1, sfList, &sfReply);
  456.  
  457.         if (sfReply.sfGood) {
  458.             PathNameFromDirID(sfReply.sfFile.vRefNum, sfReply.sfFile.parID, worldName);
  459.             PLstrcpy(titleStr, sfReply.sfFile.name);
  460.             PLstrcat(worldName, sfReply.sfFile.name);
  461.             strcpy(gWorldFileName, p2cstr(worldName));
  462.         }
  463.     }
  464.  
  465.     /* Open window... */
  466.     gMainWindow = GetNewCWindow(rWindowID, nil, (WindowPtr)-1);
  467.     FailNil(gMainWindow);
  468.  
  469.     SetPort(gMainWindow);
  470.     TextFont(monaco);
  471.     TextSize(12);
  472.     TextMode(srcCopy);
  473.     SizeWindow(gMainWindow, SCREEN_WIDTH, SCREEN_HEIGHT + kBottomBorder, false);
  474.     SetWTitle(gMainWindow, titleStr);
  475.  
  476.     ShowWindow(gMainWindow);
  477.  
  478.     // Kludge the zoomRects so we toggle between "micro" and "normal" sizes.
  479.  
  480.     wHndl = (WStateData **)((WindowPeek)gMainWindow)->dataHandle;
  481.     (*wHndl)->stdState.top = (*wHndl)->userState.top;
  482.     (*wHndl)->stdState.left = (*wHndl)->userState.left;
  483.     (*wHndl)->stdState.bottom = (*wHndl)->stdState.top + (SCREEN_HEIGHT<<1) + kBottomBorder;
  484.     (*wHndl)->stdState.right = (*wHndl)->stdState.left + (SCREEN_WIDTH<<1);
  485.  
  486.     gWTFTWindow = gMainWindow;
  487.     InitDirScrnGraphicsWindow(gMainWindow, initPal);
  488. }
  489.  
  490.  
  491. /**/
  492.  
  493.  
  494. void TogglePause(void)
  495. {
  496.     Str255    aStr;
  497.  
  498.     if (gGameOn) {
  499.         gPaused = !gPaused;
  500.     
  501.         GetIndString(aStr, rUtilityStrs, (gPaused) ? rStrContinue : rStrPause);
  502.         SetItem(gFileMenu, rFilePause, aStr);
  503.     }
  504. }
  505.  
  506.  
  507. /**/
  508.  
  509.  
  510. static void doMenu(long mResult)
  511. {
  512.     int            theMenu, theItem;
  513.     Str255        daName;
  514.     char        compilerStr[64], dateTimeStr[64];
  515.     GrafPtr        savePort;
  516.     
  517.     theItem = LoWord(mResult);
  518.     theMenu = HiWord(mResult);
  519.  
  520.     switch (theMenu) {
  521.  
  522.     case rAppleMenuID:
  523.         if (theItem == rAppleAbout) {
  524.             GetIndString(daName, rUtilityStrs, CheckDirScrnWriteFor(gMainWindow) ? rDirWrite : rNoDirWrite);
  525.  
  526. #if   applec
  527. #define    idStr    "MPW C"
  528. #elif __MWERKS__
  529. #define    idStr    "Metrowerks"
  530. #elif THINK_C || THINK_CPLUS
  531. #define    idStr    "THINK C"
  532. #elif    __powerc
  533. #define    idStr    "PPCC"
  534. #endif
  535.             strcpy(dateTimeStr, __DATE__);
  536.             strcat(dateTimeStr, ", ");
  537.             strcat(dateTimeStr, __TIME__);
  538.             strcpy(compilerStr, "Compiler: ");
  539.             strcat(compilerStr, idStr);
  540.             strcat(compilerStr, 
  541. #if    __powerc
  542.                     " PowerPC");
  543. #else
  544.                     " 68K");
  545. #endif
  546.  
  547.             ParamText(gWTVersion, daName, c2pstr(compilerStr), c2pstr(dateTimeStr));
  548.             Alert(rAboutAlert, nil);
  549.  
  550. #undef    idStr
  551.  
  552.         }
  553.         else {
  554.             GetItem(gAppleMenu, theItem, daName);
  555.             GetPort(&savePort);
  556.             (void) OpenDeskAcc(daName);
  557.             SetPort(savePort);
  558.         }
  559.         break;
  560.  
  561.     case rFileMenuID:
  562.         switch (theItem) {
  563.         case rFileNewGame:
  564.             BeginGame();
  565.             break;
  566.  
  567.         case rFileUseQD:
  568.             gUseQuickDraw = !gUseQuickDraw;
  569.             SetItemMark(gFileMenu, theItem, (gUseQuickDraw) ? checkMark : noMark);
  570.             break;
  571.  
  572.         case rFilePause:
  573.             TogglePause();
  574.             break;
  575.  
  576.         case rFileShowFPS:
  577.             gShowFPS = !gShowFPS;
  578.             SetItemMark(gFileMenu, rFileShowFPS, (gShowFPS) ? checkMark : noMark);
  579.             break;
  580.  
  581.         case rFileQuit:
  582.             gDone = gGameOn = true;
  583.             break;
  584.         }
  585.         break;
  586.  
  587.     case rEditMenuID:
  588.         if (!SystemEdit(theItem-1))
  589.             SysBeep(0);
  590.         break;
  591.  
  592.     default:
  593.         break;
  594.     }
  595.     HiliteMenu(0);
  596. }
  597.  
  598.  
  599. /**/
  600.  
  601.  
  602. static void FixupMenus(void)
  603. {
  604.     if (gGameOn) {
  605.         DisableItem(gFileMenu, rFileNewGame);    // no more new games!
  606.         EnableItem(gFileMenu, rFilePause);
  607.     }
  608.     else
  609.         DisableItem(gFileMenu, rFilePause);
  610. }
  611.  
  612.  
  613. /**/
  614.  
  615.  
  616. int GetAndProcessEvent(void)
  617. {
  618.     WindowPtr        whichWindow;
  619.     long            menuResult;
  620.     short            partCode;
  621.     int                result = gotNoEvent;
  622.     char            ch;
  623.  
  624.     if (WaitNextEvent(everyEvent, &gTheEvent, gYieldTime, nil)) {
  625.  
  626.         result = gotOtherEvent;
  627.  
  628.         switch (gTheEvent.what) {
  629.  
  630.         case mouseDown:
  631.  
  632.             switch (partCode = FindWindow(gTheEvent.where, &whichWindow)) {
  633.  
  634.             case inSysWindow:
  635.                 SystemClick(&gTheEvent, whichWindow);
  636.                 break;
  637.  
  638.             case inMenuBar:
  639.                 FixupMenus();
  640.                 doMenu(MenuSelect(gTheEvent.where));
  641.                 break;
  642.  
  643.             case inDrag:
  644.                 SelectWindow(whichWindow);
  645.                 DragWindow(whichWindow, gTheEvent.where, &qd.screenBits.bounds);
  646.                 break;
  647.  
  648.             case inContent:
  649.                 if (whichWindow != FrontWindow())
  650.                     SelectWindow(whichWindow);
  651.                 break;
  652.  
  653.             case inGoAway:
  654.                 if (TrackGoAway(whichWindow, gTheEvent.where)) {
  655.                     ExitToShell();
  656.                 }
  657.                 break;
  658.  
  659.             case inZoomIn:
  660.             case inZoomOut:
  661.                 if (TrackBox(whichWindow, gTheEvent.where, partCode)) {
  662.                     SetPort(whichWindow);
  663.                     EraseRect(&whichWindow->portRect);
  664.                     ZoomWindow(whichWindow, partCode, whichWindow == FrontWindow());
  665.                     InvalRect(&whichWindow->portRect);
  666.                 }
  667.                 break;
  668.  
  669.             default:
  670.                 break;
  671.  
  672.             }                                // switch (FindWindow)
  673.             break;
  674.  
  675.  
  676.         case keyDown:
  677.             ObscureCursor();
  678.             // FALL THRU
  679.  
  680.         case autoKey:
  681.             ch = gTheEvent.message;            // automagic "& charCodeMask" :)
  682.             if (gTheEvent.modifiers & cmdKey) {
  683.                 FixupMenus();
  684.                 menuResult = MenuKey(ch);
  685.                 if (menuResult & 0xFFFF0000) {
  686.                     doMenu(menuResult);
  687.                     break;        // out of this switch if it was a menu command
  688.                 }
  689.             }
  690.             else
  691.             if (ch == kTab || ch == kEsc)    // tab/esc ==> pause game
  692.                 TogglePause();
  693.  
  694.             // FALL THRU
  695.  
  696.         case keyUp:                // if we ever switch these on...
  697.             result = gotKeyEvent;
  698.             break;
  699.  
  700.  
  701.         case updateEvt:
  702.             whichWindow = (WindowPtr)gTheEvent.message;
  703.             BeginUpdate(whichWindow);
  704.  
  705.             if (whichWindow == gMainWindow)
  706.                 RefreshWTWindow();
  707.  
  708.             EndUpdate(whichWindow);
  709.             break;
  710.  
  711.         case diskEvt:
  712.             break;
  713.  
  714.         case activateEvt:
  715.             break;
  716.  
  717.         case app4Evt:
  718.             if ((gTheEvent.message << 31) == 0) {    // suspend event
  719.                 if (!gPaused)
  720.                     TogglePause();
  721.                 gYieldTime = 60*60;
  722.                 gInBackground = true;
  723.             }
  724.             else {
  725.                 gYieldTime = 0;
  726.                 gInBackground = false;
  727.                 SetPort(gMainWindow);
  728.             }
  729.             break;
  730.  
  731.         case kHighLevelEvent:
  732.             AEProcessAppleEvent(&gTheEvent);
  733.             break;
  734.  
  735.         default:
  736.             break;
  737.         }                                        // switch (gTheEvent.what)
  738.     }
  739.  
  740.     return result;
  741. }
  742.  
  743.  
  744. /**/
  745.  
  746.  
  747. void main(void)
  748. {
  749.     char    *myArgs[3];
  750.  
  751.     extern int WTMain(int argc, char **argv);
  752.  
  753.     // chocks away...
  754.  
  755.     init();
  756.  
  757.     myArgs[0] = "wtft";
  758.  
  759.     myArgs[1] = (char *)gWorldFileName;
  760.     myArgs[2] = 0;
  761.  
  762.     while (GetAndProcessEvent())
  763.         ;
  764.  
  765.     WTMain(2, myArgs);
  766. }
  767.